package site.yunnong.atvris.common.exception;


import site.yunnong.atvris.common.api.ResultCodeEnum;

/**
 * @author JinghaoZhang
 * @date 2021年-04月-10日
 */
public class YunnongBusinessException extends RuntimeException {

    private ResultCodeEnum resultCode;

    public YunnongBusinessException(ResultCodeEnum resultCode) {
        this(resultCode, resultCode.getMessage());
    }

    public YunnongBusinessException(ResultCodeEnum resultCode, String message) {
        super(message);
        this.resultCode = resultCode;
    }

    public YunnongBusinessException(ResultCodeEnum resultCode, Throwable cause) {
        this(resultCode, resultCode.getMessage(), cause);
    }

    public YunnongBusinessException(ResultCodeEnum resultCode, String message, Throwable cause) {
        super(message, cause);
        this.resultCode = resultCode;
    }

    public ResultCodeEnum getResultCode() {
        return this.resultCode;
    }

    @Override
    public String toString() {
        String message = this.resultCode.getMessage();
        if (this.getLocalizedMessage() != null) {
            message = message + "," +this.getLocalizedMessage();
        }
        return this.getClass().getName() + ": " + message;
    }
}
